﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.stage;
using Imaginecup.util;
using Imaginecup.util.collision;
using Imaginecup.stateManager;
using Imaginecup.factory;
using Imaginecup.gameState.menu;
using Imaginecup.gameState.water.mapMan;
using Imaginecup.gameState.water.controller;

namespace Imaginecup.gameState.water.stage
{
    public class Stage1 : IStageLoop, IStage 
    {
        private IStageManController m_StageController;

        private IController m_Controller;
        private bool m_EndStage = false;

        private MapMan m_MapMan;

        public Stage1()
        {
#if WINDOWS
            m_Controller = new WindowController();
#endif
#if WINDOWS_PHONE
            m_Controller = new PhoneController();
#endif
            m_MapMan = new MapMan();
            m_Controller.SetMapManager(m_MapMan);

            
           }

        public void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            //IMouseInputHandler mouseInput = MouseInputHandler.GetInputHandler();

            //if (mouseInput.IsOneClickUp() )//&& Collision.CollisionByPoint((EntityInfo)m_MenuIcon.GetEntityInfo(),                mouseInput.Position))
            //{
            //    GameStateManager stateMan = shareData.StateShareData.GetShareData().GetGameStateMan();

            //    IFactory factory = StateFactory.GetStateFactory();

            //    IGameState menuState = (IGameState)factory.GetObject(StateFactoryID.State_Menu);
            //    IMenuController menuControl = (IMenuController)menuState;

            //    menuControl.SetChooseControl((IChooseControl)m_StageController);
            //    menuControl.SetResetController((IResetController)m_StageController);

            //    stateMan.PushState(menuState);

            //    return;
            //}

            m_Controller.Update(gameTime);
            m_MapMan.Update(gameTime);

            //if (m_EndStage)
            //    UnloadResource();
        }

        public void Draw(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (m_EndStage) return;
            m_MapMan.Draw(gameTime, spriteBatch);
            m_Controller.Draw(gameTime, spriteBatch);
        }

        public void SetStageMan(IStageManController stageMan)
        {
            m_StageController = stageMan;
        }

        public void Release()
        {
        }

        public void SetGameOver()
        {
            m_StageController.ChangeStage(StageEnum.ChoiceStage);
            m_EndStage = true;
        }
        public void SetClear()
        {
            m_StageController.SetClear();
            m_EndStage = true;
        }

        public  void CheckGameState()
        {
            //if (LifeMan.GetLifeMan().GetLifeCount() == 0)
            //{
            //    SetGameOver();
            //}


            //else if (m_ObjectMan.GetNumofComponent(ComponentTypeID.CID_CHILDREN_ENTITY) == 0 && m_ChildGenerator.GetChildNum() == 0)
            //{
            //    ChangeStage(StageEnum.Stage2);
            //}

        }

        public void ChangeStage(StageEnum stageEnum)
        {
            m_StageController.SetEnableChoice(stageEnum);
            m_StageController.ChangeStage(StageEnum.ChoiceStage);
            m_EndStage = true;
        }
    }
}
